/*
 * ShotHttpSender.h
 *
 *  Created on: Oct 7, 2012
 *      Author: Administrator
 */

#ifndef SHOTHTTPSENDER_H_
#define SHOTHTTPSENDER_H_

#include <FNet.h>
#include <FBaseRt.h>
#include "IShotSender.h"

class ShotHttpSender :
	public IShotSender,
	public Osp::Net::Http::IHttpTransactionEventListener,
	public Osp::Base::Runtime::Thread

{
	public:
		ShotHttpSender();
		virtual ~ShotHttpSender();
	public:
		virtual void SendShot(Shot* shot);
	public:
		virtual void OnTransactionAborted (Osp::Net::Http::HttpSession &httpSession, Osp::Net::Http::HttpTransaction &httpTransaction, result r);
		virtual void OnTransactionCertVerificationRequiredN (Osp::Net::Http::HttpSession &httpSession, Osp::Net::Http::HttpTransaction &httpTransaction, Osp::Base::String *pCert);
		virtual void OnTransactionCompleted (Osp::Net::Http::HttpSession &httpSession, Osp::Net::Http::HttpTransaction &httpTransaction);
		virtual void OnTransactionHeaderCompleted (Osp::Net::Http::HttpSession &httpSession, Osp::Net::Http::HttpTransaction &httpTransaction, int headerLen, bool bAuthRequired);
		virtual void OnTransactionReadyToRead (Osp::Net::Http::HttpSession &httpSession, Osp::Net::Http::HttpTransaction &httpTransaction, int availableBodyLen);
		virtual void OnTransactionReadyToWrite (Osp::Net::Http::HttpSession &httpSession, Osp::Net::Http::HttpTransaction &httpTransaction, int recommendedChunkSize);
	public:
		result Construct(void);
		virtual bool OnStart(void);
		virtual void OnStop(void);
		virtual void OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList *pArgs);
	private:
		Osp::Net::Http::HttpTransaction* transaction;
		Osp::Net::Http::HttpSession* session;
		Osp::Net::Http::HttpRequest* request;
		Osp::Base::String hostAddr;
	private:
		void TestGet(Shot* shot);
		void TestPost(Shot* shot);
		void LogHeaders(Osp::Net::Http::HttpRequest* request);
		bool __isLastData;

};

#endif /* SHOTHTTPSENDER_H_ */
